<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<head>
    <title>评审管理1</title>
    <link rel="stylesheet" href="/static/plugin/layui/css/layui.css" media="all" />
    <!--<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>-->
    <script src="/static/plugin/jquery/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="/static/plugin/layui/layui.js"></script>
    <script type="text/javascript" src="/static/js/base.js"></script>
    <script type="text/javascript" src="/static/js/formSelects.js"></script>
    <script type="text/javascript" src="/static/js/highcharts.js"></script>
<body class="layui-anim">
<!--左边表格-->
<div class="x-body">
    &nbsp;
    <div class="layui-row" style="margin-bottom: 18px;">
        <div class="layui-form">
            <div class="layui-input-inline">
                <div class="layui-input-inline" style="width: 150px">
                    <input class="layui-input" id="keyword01" placeholder="请输入名称" style="width: 150px">
                </div>
                <button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
                <!--<button class="layui-btn" id="select_detail"><i class="layui-icon layui-icon-biaodan"></i>查看</button>-->
               <!-- <button class="layui-btn" id="select_pdf"><i class="layui-icon layui-icon-xiazai"></i>查看PDF</button>-->
                <button class="layui-btn" id="appraise"><i class="layui-icon layui-icon-duigou"></i>评审</button>


                <!--<button class="layui-btn" id="appraise_submit"><i class="layui-icon layui-icon-duigou"></i>提交</button>-->
            </div>
        </div>
    </div>
    <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
    <input hidden id="pid" name="pid">
    <button id="chartShow" onclick="chartShow1()" hidden></button>
</div>
<!--评审详情框-->
<div id="detailDiv" style="display:none">
    <table class="layui-hide" id="detailList" lay-filter="detailList"></table>
</div>
<!--评审框-->
<div id="appraiseDiv" style="display:none">
    <form class="layui-form" id="appraiseFormID" style="margin-top:20px">
        <input hidden id="id" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">项目名称</label>
            <div class="layui-input-inline" style = "width:300px;">
                <input type="text" id="pname" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">
                判定等级<span style="color: red">*</span>
            </label>
            <div class="layui-input-inline" style = "width:300px;">
                <select lay-verify="cid" id="level" name="level" lay-search="">
                    <option value="1">一等奖A</option>
                    <option value="2">一等奖B</option>
                    <option value="3">一等奖C</option>
                    <option value="4">二等奖A</option>
                    <option value="4">二等奖B</option>
                    <option value="4">二等奖C</option>
                    <option value="4">三等奖A</option>
                    <!--<option>二等奖B</option>
                    <option>二等奖C</option>-->
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">评审人</label>
            <div class="layui-input-inline" style = "width:300px;">
                <input type="text" th:value="${session.user.username}" readonly autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item" style="margin-left: 70px">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-blue" lay-submit lay-filter="appraiseform" id="appraiseSubform">提交</button>
                <button class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>
    </form>
</div>

<script type="text/html" id="toolBar">
    {{# if(d.state== 1){}}
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="introduction">项目简介</a>
    {{# } else { }}
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="introduction">项目简介</a>
    <a class="layui-btn layui-btn-xs  layui-btn-normal" lay-event="edit">确认评审</a>
    {{# } }}
</script>

<script>
    $(document).ready(function () {
        var time = new Date();
        var day = ("0" + time.getDate()).slice(-2);
        var month = ("0" + (time.getMonth() + 1)).slice(-2);
        var today = time.getFullYear() + "-" + (month);
        $('#dateTime').val(today);
    })

    layui.use(['table','layer','upload','form','laydate','element'], function(){
        var table = layui.table;
        var form=layui.form;
        var laydate = layui.laydate;
        var element = layui.element;

        var $ = layui.jquery, active = {
            reload:function () {
                table.reload('contentTable',{
                    method:'get'
                    ,where:{
                        'realName':$('#keyword01').val()
                    }
                    ,page: {
                        curr: 1//重新从第 1 页开始
                    }
                });
            }
        }

        table.render({
            elem: '#tableList'
            ,id:'contentTable'
            ,url: '/appraise/selectProjectByUser'
            ,cols: [
                [ //表头
                    {field: 'id',type: 'checkbox', align:'center', fixed: 'left'},
                    {field:'uid', title:'序号', width: 55, type:'numbers',align:'center'}
                    ,{field: 'pname', title: '名称',
                    templet: function(d) {
                        return d.project.pname;
                    }
                }
                    ,{field: 'pnumber', title: '项目序号', width:160,
                    templet: function(d) {
                        return d.project.pnumber;
                    }
                }
                    ,{field: 'type', title: '类型', width:100,
                    templet: function(d) {
                        return d.project.type;
                    }
                }
                    ,{field: 'awards', title: '评审结论', width:100,
                    templet: function(d) {
                        var level = "其他";
                        if (d.project.awards == "1"){
                            level = '一等奖A';
                        }else if (d.project.awards == "2"){
                            level = '一等奖B';
                        }else if (d.project.awards == "3"){
                            level = '一等奖C';
                        }else if (d.project.awards == "4"){
                            level = '二等奖A';
                        }else if (d.project.awards == "4"){
                            level = '二等奖B';
                        }else if (d.project.awards == "4"){
                            level = '二等奖C';
                        }else if (d.project.awards == "4"){
                            level = '三等奖A';
                        }
                        return level;
                    }
                }
                    ,{field: 'level', title: '我的评审', width:100,
                    templet: function(d) {
                        var level = "其他";
                        if (d.level == "1"){
                            level = '一等奖A';
                        }else if (d.level == "2"){
                            level = '一等奖B';
                        }else if (d.level == "3"){
                            level = '一等奖C';
                        }else if (d.level == "4"){
                            level = '二等奖A';
                        }else if (d.level == "4"){
                            level = '二等奖B';
                        }else if (d.level == "4"){
                            level = '二等奖C';
                        }else if (d.level == "4"){
                            level = '三等奖A';
                        }
                        return level;
                    }
                }
                    ,{field: 'remark', title: '操作', toolbar: "#toolBar", width: 200}
                ]
            ]
            , page: true
            ,totalRow: true
            ,done : function(res, curr, count){
                $('th').css({
                    'background-color': '#3388CB', 'color': '#fff','font-weight':'bold',
                })
            }
        });

        //监听行单击事件（双击事件为：rowDouble）
        table.on('rowDouble(tableList)', function(obj){
            var url2 =  obj.data.project.url;
            window.location.href = "/static/pdf/"+url2;
        });

        //监听行工具事件
        table.on('tool(tableList)', function(obj){
            if(obj.event === 'edit'){
                layer.confirm('确定提交吗？提交后不可更改审批结果', function(index){
                    var id = obj.data.id;
                    $.ajax({
                        type:'post',
                        url:'/appraise/submit',
                        data:{"id":id},
                        success:function(res){
                            if (res == true) {
                                layer.alert("提交成功！");
                                table.reload('contenttable',{
                                    method:'get',
                                    page: {
                                        curr: 1//重新从第 1 页开始
                                    }
                                });
                            }else{
                                layer.alert("提交失败！请联系管理员");
                                table.reload('contenttable',{
                                    method:'get',
                                    page: {
                                        curr: 1//重新从第 1 页开始
                                    }
                                });
                            }
                        }

                    })
                    layer.close(index);
                });
            }else if(obj.event === 'introduction'){
                var ppt = obj.data.project.ppt;
                window.location.href = "/project/introduction?fileName="+ppt;
            }
        });

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.layui-col-md12 .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.select .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //评审
        $("#appraise").click(function(){
            var rowData = table.checkStatus('contentTable');
            var data = rowData.data;
            if(data.length == 0){
                layer.alert("请勾选要操作的项！",{icon :5})
            }else if(data[0].state == 1){
                layer.alert("已提交不能再评审！",{icon :5})
            } else {
                layer.open({
                    type: 1 ,				//Page层类型
                    area: ['540px', '420px'] 	//宽  高
                    ,title: '评审'
                    ,shade: 0.6 			//遮罩透明度
                    ,maxmin: true 			//允许全屏最小化
                    ,anim: 1 				//0-6的动画形式，-1不开启
                    ,content: $('#appraiseDiv')
                    ,success: function(){
                        $("input[name='id']").val(data[0].id);
                        $("#pname").val(data[0].project.pname);
                        form.render();
                    }
                });
            }
        });

        /**  data:{itemName:"12",startDate:'2019-09-20'},
         * 通用表单提交(AJAX方式),totalMoney:100,startDate:'2019-09-20',dueDate:'2019-09-20'
         */
        form.on('submit(appraiseform)', function () {
            var formData = $("#appraiseFormID").serialize();
            $("#subBtn").attr("disabled",true);
            $.ajax({
                type:'post',
                url:'/appraise/appraise',
                data:formData,
            }).done(
                function(res) {
                    if (res == true) {
                        layer.msg('评审成功',{icon:1})
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }else {
                        layer.msg("请联系管理员！",{icon:2})
                    }
                }
            ).fail(
                function() {
                    layer.msg('请联系管理员',{icon:2})
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })
    });
</script>
</body>

</html>